#include <iostream>
#include <iomanip>
#include <ctype.h>

#include "SelectionMenu.h"

using std::pair;
using std::cout;
using std::endl;
using std::left;
using std::setw;
using std::cin;
using std::getline;

//Constructors

SelectionMenu::SelectionMenu(string infoBar, string basicAction): GeneralMenu(infoBar)
{
	selection.insert(pair<int, string>(0, basicAction));
}

//Member Functions

void SelectionMenu::displayContent()
{
	for (int i = 1; i < selection.size(); i++)
	{
		cout << left << setw(3) << i + ".";
		cout << selection[i];
		cout << endl;
	}

	cout << "0. " << selection[0] << endl;
}

void SelectionMenu::addSelection(string choice)
{
	selection.insert(pair<int, string>(selection.size(), choice));
}

int SelectionMenu::getSelectionFromUser() const
{
	string userInput;
	int userSelection;

	do {
		cout << "Please input your selection(0-" << selection.size() - 1 << "): ";
		getline(cin, userInput);

		userSelection = atoi(userInput.c_str());

		if (userSelection == 0 && userInput[0] != 0)
		{
			userSelection = -1;
			cout << "Invalid input! ";
		}
	} while (userSelection < 0 || userSelection >= selection.size());

	return userSelection;
}